<?
	/* Se asegura que el archivo es incluido por el index */
	defined( 'LOAD_MODULE_ACTION' ) or die( 'No esta permitido el acceso directo a ' . __FILE__ );
		$this->oTmpObject = new Ticket_frm( $this );

	class Ticket_frm extends Frm
	{
	function setValue ( $ncTicket )
		{
			$cSql = "SELECT  ncAccion,  ncTipoTicket,  ncSolicitante,  ncComputadora,  cProblema,  cProblemaTecnico,  cObstaculos,  dAlta,  dRealizado,  ncArea,  ncUsuario,  dVencimiento
				FROM atTicket
				WHERE ncTicket = '$ncTicket' ";
			$aDatos = $this->oDatabase->getArray($cSql);
			$this->setFieldsArray ( $aDatos );
		}
	function Ticket_frm( &$oModule )
		{
			$this->Frm( $oModule );
			//Crea los Objetos de los campos de edicion
			$this->aFields['ncTicket']				= new Input( "Codigo", "ncTicket", '', false, true );
			$this->aFields['ncUsuario']				= new Input( "Codigo Usuario", "ncUsuario", '', false, true );
			$this->aFields['ncAccion']				= new InputList( "Accion", "ncAccion" );
			$this->aFields['ncTipoTicket']				= new InputList( "Tipo","ncTipoTicket" );
			$this->aFields['ncSolicitante']				= new InputLookUp( "Solicitante", "ncSolicitante" );
			$this->aFields['ncComputadora']				= new InputLookUp( "Computadora", "ncComputadora" );
			$this->aFields['cProblema']				= new InputText( "Descripcion", "cProblema" );
			$this->aFields['cProblemaTecnico']				= new InputText( "Descripcion tecnica", "cProblemaTecnico" );
			$this->aFields['cObstaculos']				= new InputText( "Obstaculos", "cObstaculos" );
			$this->aFields['dAlta']				= new InputDate( "Alta", "dAlta" );
			$this->aFields['dRealizado']				= new InputDate( "Realizado", "dRealizado" );
			$this->aFields['ncArea']				= new InputList( "Area", "ncArea" );
			$this->aFields['dVencimiento']				= new InputDate( "Vencimiento", "dVencimiento" );
		}
	function setLevel( $nLevel)
		{
			switch ( $nLevel )
			{
				case 1:
					$this->aInput = array ('ncTicket', 'ncAccion', 'ncTipoTicket', 'ncSolicitante', 'ncComputadora' );
					break;
				case 2:
					$this->aInput = array ('ncTicket','ncSolicitante','ncTipoTicket','cProblema' );
					break;
				case 3:
					$this->aInput = array ('ncTicket','ncSolicitante','ncComputadora','ncArea','ncTipoTicket', 'cProblema','ncAccion','cProblemaTecnico','cObstaculos');
					break;
			}
		}
	function initializeForm()
		{
			// Si viene el Ubicacion hace el retrieve
				if ( $this->isRetrievable() && $this->aFields['ncTicket']->getValue() )
				{
					$this->setValue( $this->aFields['ncTicket']->getValue() );
				}
			// Configura el Titulo
				$this->setLabel( "Ticket" );
			return true;
		}
	function initializeField( $cField , &$oField )
		{
			switch ( $cField )
			{
					case 'ncAccion':
						$cSql = "SELECT ncAccion, ncAccion FROM acAccionTicket";
						$oField->setMatrix($this->oDatabase->getMatrix($cSql));
					break;
					case 'ncTipoTicket':
						$oField->setForm( $this );
						$oField->setOnChangeAutoSubmit( $this );
						$cSql = "SELECT ncTipoTicket, cdTipoTicket FROM atTipoTicket";
						$oField->setMatrix($this->oDatabase->getMatrix($cSql));
						$oField->addActionArray( 2, $this->oModule->getActionArray( AGREGAR_TIPO_TICKET), $cParametros , $cField);
						$oField->addActionArray( 3, $this->oModule->getActionArray( MODIFICAR_TIPO_TICKET), $cParametros, $cField );
					break;
					case 'ncSolicitante':
						$oField->setForm( $this );
						$oField->setDefault($this->oModule->oUserSession->getUser() );
						$oField->setFieldActions( 'ncPersona');
						initializePersonal( $oField ) ;
						$oField->setMandatory($this->isMandatory);
						$oField->setOnChangeAutoSubmit( $this);
					break;
					case 'ncComputadora':
						$oField->setForm( $this );
						if ( $this->aFields['ncSolicitante']->getValue()  )
						{
							$cSql = "SELECT ncComputadora FROM atComputadora WHERE ncPersona = " .  $this->aFields['ncSolicitante']->getValue()  ;
							$ncComputadora = $this->oDatabase->getData($cSql);
							$oField->setDefault($ncComputadora) ;
						}
						initializeComputadora( $oField , '', 'ncSolicitante_Key');
					break;
					case 'cProblema':
						$oField->setEditor();
						if ( $this->aFields['ncTipoTicket']->getValue()  )
						{
							$cSql = "SELECT cDescripcion FROM atTipoTicket WHERE ncTipoTicket = " .  $this->aFields['ncTipoTicket']->getValue()  ;
							$oField->setDefault($this->oDatabase->getData($cSql)) ;
						}
					break;
					case 'cProblemaTecnico':
						$oField->setEditor();
					break;
					case 'cObstaculos':
						$oField->setEditor();
					break;
				case 'ncArea':
					$cSql = "SELECT ncArea, cdArea FROM atOrganizacionArea
												WHERE ncOrganizacion = " . CODIGO_ORGANIZACION. " ORDER BY cdArea";
					$oField->setMatrix( $this->oDatabase->getMatrix($cSql)  );
					if ( $this->aFields['ncSolicitante']->getValue()  )
					{
						$cSql = "SELECT ncArea FROM atOrganizacionPersona WHERE ncOrganizacion = " . CODIGO_ORGANIZACION . " AND ncPersona = " .  $this->aFields['ncSolicitante']->getValue()  ;
						$ncArea = $this->oDatabase->getData($cSql);
						$oField->setDefault($ncArea) ;
					}
					break;
			}
 		}
	}
?>